//
//  ActivityDetailCell.m
//  TourPlay
//
//  Created by dllo on 15/11/23.
//  Copyright © 2015年 王军岐. All rights reserved.
//

#import "ActivityDetailCell.h"

@interface ActivityDetailCell ()

@property (nonatomic, retain) UIImageView *backgroundImageV;
@property (nonatomic, retain) UIImageView *imageV;
@property (nonatomic, retain) UILabel *titleL;

@end


@implementation ActivityDetailCell
- (void)dealloc
{
    [_titleL release];
    [_imageV release];
    [_activityMod release];
    [super dealloc];
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}
- (void)createSubViews
{
    self.backgroundImageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT * (2.3f / 5.f))];
    //    self.backgroundImageV.backgroundColor = [UIColor brownColor];
    //    self.backgroundImageV.image = [UIImage imageNamed:@"wode_morenbg@2x.jpg"];
    [self.contentView addSubview:self.backgroundImageV];
    [_backgroundImageV release];
    
    
    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    
    UIVisualEffectView *blurView = [[UIVisualEffectView alloc] initWithEffect:effect];
    blurView.frame = self.backgroundImageV.bounds;
    [self.backgroundImageV addSubview:blurView];
    [blurView release];
    
    
    self.imageV = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, self.backgroundImageV.frame.size.width - 40, self.backgroundImageV.frame.size.height - 40)];
    self.imageV.backgroundColor = [UIColor clearColor];
    self.imageV.contentMode = UIViewContentModeScaleAspectFit;
    [self.backgroundImageV addSubview:self.imageV];
    [_imageV release];
    
    [self.imageV bringSubviewToFront:self.backgroundImageV];
    
    
    self.titleL = [[UILabel alloc] initWithFrame:CGRectMake(20, self.backgroundImageV.frame.size.height + 0, SCREEN_WIDTH - 40, 80)];
//    self.titleL.backgroundColor = [UIColor whiteColor];
    self.titleL.textAlignment = NSTextAlignmentCenter;
    self.titleL.numberOfLines = 0;
    self.titleL.font = [UIFont boldSystemFontOfSize:18.5f];
    // 自适应字体大小
    self.titleL.adjustsFontSizeToFitWidth = YES;
//    self.titleL.font = [UIFont systemFontOfSize:20.f];
    [self.contentView addSubview:self.titleL];
    [_titleL release];
    
    // 夜间模式
    [self addColorChangedBlock:^{
        
        self.contentView.nightBackgroundColor = [ColorSingleton shareSingleton].cellColor;
        self.contentView.normalBackgroundColor = [ColorSingleton shareSingleton].cellColor;
        
        self.titleL.nightTextColor = [ColorSingleton shareSingleton].cellTitleColor;
        self.titleL.normalTextColor = [ColorSingleton shareSingleton].cellTitleColor;
        
    }];
}
- (void)setActivityMod:(ActivityModel *)activityMod
{
    if (_activityMod != activityMod) {
        [_activityMod release];
        _activityMod = [activityMod retain];
    }
    NSURL *url = [NSURL URLWithString:self.activityMod.pic];
    [self.imageV sd_setImageWithURL:url placeholderImage:PICHOLDEER];
    
    [self.backgroundImageV sd_setImageWithURL:url placeholderImage:PICHOLDEER];

    
    self.titleL.text = self.activityMod.title;
    
  
}

- (CGFloat)getCellHeight
{
    NSLog(@"--%f", SCREEN_HEIGHT * (2.3f / 5.f) + 80);
    NSLog(@"%f", self.titleL.frame.origin.y + self.titleL.frame.size.height);
    return self.titleL.frame.origin.y + self.titleL.frame.size.height;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
